<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html class="no-js fixed-layout">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Listen 美食城|美味小吃|营养丰富</title>
  <meta name="description" content="这是一个 index 页面">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="/Public/vendor/assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="/Public/vendor/assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="/Public/vendor/assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="/Public/vendor/assets/css/admin.css">
  <link rel="stylesheet" href="/Public/vendor/nprogress/nprogress.css">

  
    <link rel="stylesheet" href="/Public/assets/admin/common.css">
    <style>
        .xChildren {
            display: none;
        }
    </style>

</head>
<body>

<!--加载动画-->
<div id="globalLoading" class="global-loading">
    <div class="global-loading-logo">
        <div id="globalLoadingAnim" class="global-loading-anim"></div>
    </div>
</div>
<!--加载动画-->
<script src="/Public/assets/admin/js/loading.js"></script>
<script>
    window.onload = function () {
        $("#globalLoading").fadeOut();
    }
</script>



<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-topbar-brand">
        <strong>Listen 美食城</strong> <small>后台管理模板</small>
    </div>

    <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
            <li><a href="javascript:;"><span class="am-icon-envelope-o"></span> 收件箱 <span class="am-badge am-badge-warning">5</span></a></li>
            <li class="am-dropdown" data-am-dropdown>
                <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
                    <span class="am-icon-users"></span> <?php echo ($_SESSION[user]['username']); ?>管理员 <span class="am-icon-caret-down"></span>
                </a>
                <ul class="am-dropdown-content">
                    <li><a href="#"><span class="am-icon-user"></span> 资料</a></li>
                    <li><a href="#"><span class="am-icon-cog"></span> 设置</a></li>
                    <li><a href="<?php echo U('User/logout');?>"><span class="am-icon-power-off"></span> 退出</a></li>
                </ul>
            </li>
            <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"><span class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>
        </ul>
    </div>
</header>


<div class="am-cf admin-main">
  <!-- sidebar start -->
  <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
    <div class="am-offcanvas-bar admin-offcanvas-bar">
        <ul class="am-list admin-sidebar-list">
            <li><a href="/admin"><span class="am-icon-home"></span> 首页</a></li>
            <li class="admin-parent">
                <a class="am-cf" data-am-collapse="{target: '#collapse-nav'}"><span class="am-icon-product-hunt am-icon-spin"></span> 商城中心
                    <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
                <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-nav">
                    <li><a href="<?php echo U('Product/index');?>" class="am-cf"><span class="am-icon-shopping-cart"></span> 商品列表<span
                            class="am-badge am-badge-success am-margin-right am-fr"><?php echo ($product_counts); ?></span></a></li>
                    <!--<li><a href="<?php echo U('Product/add');?>"><span class="am-icon-puzzle-piece"></span> 商品管理</a></li>-->
                    <li><a href="<?php echo U('Category/index');?>"><span class="am-icon-calendar"></span> 分类管理</a></li>
                    <li><a href="<?php echo U('Gallery/index');?>"><span class="am-icon-photo"></span> 商品相册<span
                            class="am-badge am-badge-secondary am-margin-right am-fr">12</span></a></li>
                    <li><a href="<?php echo U('Advert/index');?>"><span class="am-icon-adjust"></span> 广告管理<span
                            class="am-badge am-badge-secondary am-margin-right am-fr"><?php echo ($advert_counts); ?></span></a></li>
                    <li><a href="<?php echo U('Customer/index');?>"><span class="am-icon-user-secret"></span> 会员管理<span
                            class="am-badge am-badge-secondary am-margin-right am-fr"><?php echo ($customer_counts); ?></span></a></li>
                    <li><a href="<?php echo U('Order/index');?>"><span class="am-icon-arrow-circle-o-right"></span> 订单管理<span
                            class="am-badge am-badge-success am-margin-right am-fr"><?php echo ($order_counts); ?></span></a></li>
                    <li><a href="<?php echo U('Recycle/index');?>"><span class="am-icon-refresh"></span> 商品回收站<span
                            class="am-badge am-badge-warning am-margin-right am-fr"><?php echo ($product_recycles); ?></span></a></li>
                </ul>
            </li>
            <li class="admin-parent">
                <a class="am-cf" data-am-collapse="{target: '#collapse-auth'}"><span class="am-icon-gear am-icon-spin"></span> 系统管理
                    <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
                <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-auth">
                    <li><a href="<?php echo U('AuthSet/user_manage');?>"><span class="am-icon-user"></span> 用户管理
                        <span class="am-badge am-badge-success am-margin-right am-fr"><?php echo ($user_counts); ?></span></a></li>
                    <li><a href="<?php echo U('AuthSet/group_manage');?>"><span class="am-icon-group"></span> 用户组管理</a></li>
                    <li><a href="<?php echo U('AuthSet/rule_manage');?>" class="<?php echo ($_menu or ''); ?>"><span class="am-icon-lock"></span> 菜单与权限</a></li>
                </ul>
            </li>
        </ul>

        <div class="am-panel am-panel-default admin-sidebar-panel">
            <div class="am-panel-bd">
                <p><span class="am-icon-bookmark"></span> 公告</p>
                <p>时光静好，与君语；细水流年，与君同。—— Amaze UI</p>
            </div>
        </div>

        <div class="am-panel am-panel-default admin-sidebar-panel">
            <div class="am-panel-bd">
                <p><span class="am-icon-tag"></span> wiki</p>
                <p>Welcome to the Amaze UI wiki!</p>
            </div>
        </div>
    </div>
</div>

  <!-- sidebar end -->

  <!-- content start -->
  
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">分类列表</strong> /
                    <small>Category List</small>
                </div>
            </div>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="<?php echo U('Category/add');?>" class="am-btn am-btn-default"><span
                                    class="am-icon-plus"></span> 新增
                            </a>
                            <button type="button" class="delete_all am-btn am-btn-danger"><span
                                    class="am-icon-trash"></span> 删除
                            </button>
                            <button type="button" id="show_all" class="am-btn am-btn-primary"><span
                                    class="am-icon-arrows"></span> 显示/隐藏分类
                            </button>
                        </div>
                    </div>
                </div>

                <form>
                    <div class="am-u-sm-12 am-u-md-3">
                        <div class="am-form-group">
                            <select name="category_id" data-am-selected="{btnWidth: '100%',  btnStyle: 'secondary', btnSize: 'sm', maxHeight: 360, searchBox: 1}">
                                <?php if(is_array($categories)): $i = 0; $__LIST__ = $categories;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$category): $mod = ($i % 2 );++$i;?><option value="<?php echo ($category["id"]); ?>"><?php echo ($category["name"]); ?></option>
                                    <!--<?php if(is_array($category["children"])): $i = 0; $__LIST__ = $category["children"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$child): $mod = ($i % 2 );++$i;?>-->
                                    <!--<option value="<?php echo ($child["id"]); ?>">-->
                                    <!--&nbsp;&nbsp;&nbsp;&nbsp;|&#45;&#45;<?php echo ($child["name"]); ?>-->
                                    <!--</option>-->
                                    <!--<?php endforeach; endif; else: echo "" ;endif; ?>--><?php endforeach; endif; else: echo "" ;endif; ?>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-3">
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" name="name" class="am-form-field">
                            <span class="am-input-group-btn">
                                <button class="am-btn am-btn-default" type="submit">搜索</button>
                            </span>
                        </div>
                    </div>
                </form>

            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" class="check_all"/>
                                </th>
                                <th>ID</th>
                                <th>分类名</th>
                                <th>分类商品</th>
                                <th>是否显示</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <?php if(is_array($categories)): $i = 0; $__LIST__ = $categories;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$category): $mod = ($i % 2 );++$i;?><tr data-id="<?php echo ($category["id"]); ?>" id="row_<?php echo ($category["id"]); ?>" class="xParent">
                                    <td>
                                        <input type="checkbox" name="ids[]" value="<?php echo ($category["id"]); ?>"
                                               class="checked_id"/>
                                    </td>
                                    <td><?php echo ($category["id"]); ?></td>
                                    <td><?php echo ($category["name"]); ?></td>
                                    <td></td>
                                    <td data-attr="<?php echo ($category["is_show"]); ?>">
                                        <?php if(($category["is_show"]) == "1"): ?><span class="am-icon-check is_show"></span>
                                            <?php else: ?>
                                            <span class="am-icon-close is_show"></span><?php endif; ?>
                                    </td>
                                    <td>
                                        <input type="hidden" name="id[]" value="<?php echo ($category["id"]); ?>">
                                        <input type="text" name="sort_order[]" value="<?php echo ($category["sort_order"]); ?>"
                                               class="sort_order am-input-sm">
                                    </td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="<?php echo U('edit',['id'=>$category[id]]);?>"
                                                   class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                        class="am-icon-pencil-square-o"></span> 编辑
                                                </a>

                                                <a href="javascript:void (0);"
                                                   class="delete am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                    <span class="am-icon-trash"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>

                                <?php if(is_array($category["children"])): $i = 0; $__LIST__ = $category["children"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$child): $mod = ($i % 2 );++$i;?><tr data-id="<?php echo ($child["id"]); ?>" id="row_<?php echo ($child["id"]); ?>" class="xChildren">
                                        <td>
                                            <input type="checkbox" name="ids[]" value="<?php echo ($child["id"]); ?>"
                                                   class="checked_id"/>
                                        </td>
                                        <td><?php echo ($child["id"]); ?></td>
                                        <td>
                                            &nbsp;&nbsp;&nbsp;&nbsp;|--<?php echo ($child["name"]); ?>
                                        </td>
                                        <td>
                                            <a href="<?php echo U('Product/index',['category_id'=>$child[id]]);?>"
                                               class="am-btn am-btn-primary am-btn-xs">查看商品</a>
                                        </td>
                                        <td data-attr="<?php echo ($child["is_show"]); ?>">
                                            <?php if(($child["is_show"]) == "1"): ?><span class="am-icon-check is_show"></span>
                                                <?php else: ?>
                                                <span class="am-icon-close is_show"></span><?php endif; ?>
                                        </td>
                                        <td>
                                            <input type="hidden" name="id[]" value="<?php echo ($child["id"]); ?>">
                                            <input type="text" name="sort_order[]" value="<?php echo ($child["sort_order"]); ?>"
                                                   class="sort_order am-input-sm">
                                        </td>
                                        <td>
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <a href="<?php echo U('edit',['id'=>$child[id]]);?>"
                                                       class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                            class="am-icon-pencil-square-o"></span> 编辑
                                                    </a>

                                                    <a href="javascript:void (0);"
                                                       class="delete am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                        <span class="am-icon-trash"></span> 删除
                                                    </a>
                                                </div>
                                            </div>
                                        </td>
                                    </tr><?php endforeach; endif; else: echo "" ;endif; endforeach; endif; else: echo "" ;endif; ?>

                            </tbody>
                        </table>
                    </form>
                    <div class="am-cf">
                        <div class="am-fr">
                            <ul class="am-pagination">

                            </ul>
                        </div>
                    </div>
                    <hr/>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

        <!--删除模态框-->
        <div class="am-modal am-modal-confirm" tabindex="-1" id="deleteCategory">
            <div class="am-modal-dialog">
                <input type="hidden" id="delete_id">

                <div class="am-modal-hd">删除分类</div>
                <div class="am-modal-bd">
                    你，确定要删除这个分类吗？
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                    <span class="delete_confirm am-modal-btn" data-am-modal-confirm>确定</span>
                </div>
            </div>
        </div>

    </div>

  <!-- content end -->

</div>

<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>


<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/Public/vendor/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/Public/vendor/assets/js/amazeui.min.js"></script>
<script src="/Public/vendor/assets/js/app.js"></script>


<!--进度条-->
<script src="/Public/vendor/nprogress/nprogress.js"></script>
<script>
  $(function () {
      //进度条
      $(document).ready(function () {
          NProgress.start();
      });

      $(window).load(function () {
          NProgress.done();
      });
  })
</script>


    <script>
        $(function () {
            //ajax删除
            $('#doc-modal-list').find('.am-icon-close').add('.delete').on('click', function () {
                $('#deleteCategory').modal();
                var id = $(this).parents('tr').data('id');
                $("#delete_id").val(id);
            });

            $(".delete_confirm").click(function () {
                var id = $("#delete_id").val();
                var _this = $("tr[data-id='" + id + "']");

                $.post("<?php echo U('ajax_delete');?>", {id: id}, function (info) {
                    if (info.status == 1) {
                        _this.fadeOut(400);
                        $('#deleteCategory').modal().hide();
                        alert(info.msg);
                    } else {
                        $('#deleteCategory').modal().hide();
                        alert(info.msg);
                    }
                })
                return false;
            });
        })

        //全选和不全选
        $(".check_all").click(function () {
            var checked = $(this).prop('checked');
            $('.checked_id').prop('checked', checked);
        })

        //下面全选中上面也全选
        $(".checked_id").click(function () {
            var allLength = $(".checked_id").length;
            var length = $('.checked_id:checked').length;
            if (allLength == length) {
                $('.check_all').prop('checked', true);
            } else {
                $(".check_all").prop('checked', false);
            }
        })

        //ajax多选删除
        $(".delete_all").click(function () {
            var length = $('.checked_id:checked').length;
            if (length == 0) {
                alert('请至少选中一条');
                return false;
            }

            $.post("<?php echo U('ajax_delete_all');?>", $(".checked_id:checked").serialize(), function (info) {
                if (info.status == 1) {
                    $(".checked_id:checked").each(function () {
                        $(this).parents('tr').fadeOut(400);
                    })
                    alert(info.msg);
                }
            })
            return false;
        })

        //ajax排序
        $(".sort_order").change(function () {
            var info = {
                id: $(this).parents('tr').data('id'),
                sort_order: $(this).val()
            }

            $.post("<?php echo U('ajax_sort_order');?>", info, function () {
                window.location.reload();
            })

            return false;
        })

        //ajax改变显示状态
        $(".is_show").click(function () {
            var info = {
                id: $(this).parents('tr').data('id'),
                is_show: $(this).parents('td').data('attr')
            };

            var _this = $(this);
            $.post("<?php echo U('ajax_is_show');?>", info, function () {
                _this.toggleClass('am-icon-check am-icon-close')
            })
            return false;
        })

        //ajax显示隐藏
        $("tr.xParent").dblclick(function () {
            $(this).toggleClass();
            $(".child_" + this.id).toggle();
        })

        $("#show_all").click(function () {
            $("tr.xParent").toggleClass();
            $("tr.xChildren").toggle('am-active');
        })

    </script>


</body>
</html>